import sys
from database.goleveldb.db import packageList
sys.path.append('.')
import deb.local
import deb.formatp
import deb.listp
import deb.package_collection
import deb.package_deps
import deb.package_files
import deb.package
import deb.reflist
import deb.remote
import deb.uploaders
import deb.version
import deb.importp

import files.mocks
import files.package_pool
import files.public

import utils.checksum
import utils.compress
import utils.config
import utils.human
import utils.utils
from typing import List,Dict,Tuple
import api.repos
import database
import api.publish
import deb.snapshot
from context.context import *
def fold(path):
    if not os.path.isfile(path) : 
        t=os.listdir(path)
        tt=[]
        while t!=[]:
            for i in t:
                n=os.path.join(path,i)
                t.remove(i)
                if not os.path.isdir(n):
                    tt.append(n)
                else:
                    # tt.append(n)
                    for k in os.listdir(n):
                        t.append(os.path.join(i,k))
        tt.sort()
        return tt
# api.repos.apiReposCreate(dict(Name='deepin',Comment='deepin册数',DefaultDistribution='aaa',DefaultComponent='main'))
# reposList=api.repos.apiReposList()
# for i in reposList:
#     print(i)
#     print(i.__dict__)
# repo=api.repos.apiReposShow('deepin')
# print(repo.__dict__)

# api.repos.apiReposPackagesAdd(dict(name='deepin',PackageRefs=['asdf']))
# from shutil import copyfile
# debDir='/var/spool/apt-mirror/mirror/archive.ubuntukylin.com/ubuntukylin/pool'
# for i in fold(debDir):
#     print(i)
#     copyfile(i,os.path.join('/root/.aptly/upload/aaa',os.path.basename(i)))
for i in os.listdir('/root/.aptly/upload/aaa'):

    api.repos.apiReposPackageFromDir(dict(name='deepin',dir='aaa',file=i,noRemove="1"))
# api.repos.apiReposPackageFromDir(dict(name='deepin',dir='aaa',file='todesk-v4.3.1.0-amd64.deb',noRemove="1",forceReplace=1))
# api.repos.apiReposPackagesShow(dict(name='deepin'))
# api.publish.apiPublishList({})
# api.publish.apiPublishRepoOrSnapshot({'prefix':'filesystem:sparkstore:',"SourceKind": "local","Signing":{"Passphrase":""}, "Sources": [{"Name": "deepin","Component":"main"}], "Architectures": ["i386", "amd64"], "Distribution": "wheezy",'ForceOverwrite':1})
# print(dir(database))
# aptlyContext=AptlyContext()
# gpgSigner=aptlyContext.GetSigner()
# print(gpgSigner.__dict__)